home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1998 #4 / Amiga Plus CD - 1998 - No. 4.iso / pd / tools / wbstars2.0 / source / wbstars_cx.c < prev    next >
C/C++ Source or Header  |  1998-01-16  |  3KB  |  137 lines

  1. /* $VER: WBStars_CX.c 2.0b4 (29 May 1997)
  2. */
  3.  
  4. #include <libraries/commodities.h>
  5. #include <libraries/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/commodities.h>
  8. #include <clib/alib_protos.h>
  9.  
  10. #include "WBStars_include.h"
  11. #include "WBStars_protos.h"
  12.  
  13. #define EVT_HOTKEY    1L
  14.  
  15. struct MsgPort    *broker_mp;
  16. CxObj    *broker, *filter, *sender, *translate;
  17.  
  18. struct NewBroker    newbroker = {
  19.     NB_VERSION,
  20.     "WBStars",        
  21.     "WBStars 2.0b5 by Alexander Pokahr",
  22.     "The Workbench Animator",
  23.     NBU_UNIQUE | NBU_NOTIFY,
  24.     0,    0,    0,    0
  25. };
  26.  
  27. ULONG cxsigflag;
  28.  
  29. char    InitCx()
  30. {
  31.     CxMsg *msg;
  32.     if( broker_mp=CreateMsgPort() )
  33.     {
  34.         newbroker.nb_Port = broker_mp;
  35.         cxsigflag = 1L << broker_mp->mp_SigBit;
  36.         newbroker.nb_Pri = CXpri;
  37.         if( broker=CxBroker(&newbroker,NULL) )
  38.         {
  39.             if( filter=CxFilter(hotkey) )
  40.             {
  41.                 AttachCxObj(broker, filter);
  42.                 if( sender=CxSender(broker_mp,EVT_HOTKEY) )
  43.                 {
  44.                     AttachCxObj(filter, sender);
  45.                     if( translate=(CxTranslate(NULL)) )
  46.                     {
  47.                         AttachCxObj(filter, translate);
  48.                         if( !CxObjError(filter) )
  49.                         {
  50.                             if( Activate() ) ActivateCxObj(broker, 1L);
  51.                             else ActivateCxObj(broker, 0L);
  52.                             return TRUE;
  53.                         }
  54.                     }
  55.                 }
  56.             }
  57.             DeleteCxObjAll(broker);
  58.             while( msg=(CxMsg *)GetMsg(broker_mp) )
  59.                 ReplyMsg((struct Message *)msg);
  60.         }
  61.         DeletePort(broker_mp);
  62.     }
  63.     return FALSE;
  64. }
  65.  
  66. void    RemovCx()
  67. {
  68.     CxMsg *msg;
  69.  
  70.     DeleteCxObjAll(broker);
  71.  
  72.     while( msg=(CxMsg *)GetMsg(broker_mp) )
  73.         ReplyMsg((struct Message *)msg);
  74.  
  75.     DeletePort(broker_mp);
  76. }
  77.  
  78. char    HandleCx()
  79. {
  80.     extern struct MsgPort    *broker_mp;
  81.     extern CxObj            *broker;
  82.     extern ULONG            cxsigflag;
  83.     CxMsg *msg;
  84.     ULONG msgid, msgtype;
  85.  
  86.     while(msg = (CxMsg *)GetMsg(broker_mp))
  87.     {
  88.         msgid = CxMsgID(msg);
  89.         msgtype = CxMsgType(msg);
  90.         ReplyMsg((struct Message *)msg);
  91.  
  92.         switch(msgtype)
  93.         {
  94.             case CXM_IEVENT:
  95.                 switch(msgid)
  96.                 {
  97.                     case EVT_HOTKEY:
  98.                         if( activated )
  99.                         {
  100.                             Inactivate();
  101.                         }
  102.                         else
  103.                         {
  104.                             Activate();
  105.                         }
  106.                         break;
  107.                 }
  108.                 break;
  109.             case CXM_COMMAND:
  110.                 switch(msgid)
  111.                 {
  112.                     case CXCMD_DISABLE:
  113.                         ActivateCxObj(broker, 0L);
  114.                         Inactivate();
  115.                         break;
  116.                     case CXCMD_ENABLE:
  117.                         if( Activate() )    ActivateCxObj(broker, 1L);
  118.                         break;
  119.                     case CXCMD_KILL:
  120.                         return FALSE;
  121.                         break;
  122.                     case CXCMD_UNIQUE:
  123.                         return FALSE;
  124.                         break;
  125.                     case CXCMD_APPEAR:
  126.                         break;
  127.                     case CXCMD_DISAPPEAR:
  128.                         break;
  129.                 }
  130.                 break;
  131.         }
  132.     }
  133.  
  134.     if( SetSignal(0L,SIGBREAKF_CTRL_C)&SIGBREAKF_CTRL_C )return FALSE;
  135.  
  136.     return TRUE;
  137. }